#define _CRT_SECURE_NO_WARNINGS    
#include<iostream>    
using namespace std;
long long int dp[26][30001];

int main() {
	int n, m, i, j;
	cin >> n >> m;
	int t[26];
	int w[26];
	for (i = 1; i <= m; i++) {
		cin >> t[i] >> w[i];
		w[i] *= t[i];
	}

	for (i = 0; i <= m; i++)dp[i][0] = 0;
	for (j = 0; j <= n; j++)dp[0][j] = 0;
	for (i = 1; i <= m; i++)for (j = 1; j <= n; j++)if (j >= t[i])dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - t[i]] + w[i]); else dp[i][j] = dp[i - 1][j];

	
	cout << dp[m][n] << endl;
	return 0;
}